package com.vpen.account.demo.controller.pub;

import com.vpen.account.demo.annotation.Resubmit;
import com.vpen.account.demo.model.req.ReqAccountUser;
import com.vpen.account.demo.service.AccountUserService;
import com.vpen.clib.result.CResult;
import com.vpen.clib.validation.group.Insert;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 描述 任何都能操作
 *
 * @author 韦鹏
 * @date 2022/8/16 10:41
 */
@RestController
@RequestMapping("${api.account.public-url}/account")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class AccountController {


    private final AccountUserService accountUserService;


    @PostMapping("create")
    @Resubmit(prefixKey = "create-user", keys = {"#user.phone", "#user.username"})
    public CResult<Boolean> insert(@Validated({Insert.class}) @RequestBody ReqAccountUser user) {
        return CResult.success(accountUserService.createUser(user));
    }


    @PostMapping("gen-code")
    @Resubmit(prefixKey = "gen-code", keys = {"#phone"})
    public CResult<String> genCode(@RequestParam("phone") String phone) {
        return CResult.success(accountUserService.genCode(phone));
    }
}
